package service

import (
	"Im/dao"
	"Im/dto"
	"Im/model"
	"go.mongodb.org/mongo-driver/bson/primitive"
)

func Login(loginDto dto.UserLoginDto) (*model.UserLogin, error) {
	pwd, err := dao.GetUserBasicByAccountPwd(loginDto.Account, loginDto.Password)
	if err != nil {
		return nil, err
	}
	return pwd, err
}

func UserDetail(Id primitive.ObjectID) (*model.UserBasic, error) {
	userDetail, err := dao.GetUserBasicById(Id)
	return userDetail, err
}

func Email(email string) error {
	err := dao.GetUserBasicByEmail(email)
	return err
}

func AddFriends(addFriendsDto dto.AddFriendsDto) {
	var user model.UserAddFriend
	user.Id = addFriendsDto.ID
	user.FriendApplication = addFriendsDto.FriendId
	user.AddType = addFriendsDto.AddType
	err := dao.AddFriends(user)
	if err != nil {

	}
}

func DeleteApplication(deleteApplication dto.AddFriendsDto) error {
	var user model.UserAddFriend
	user.Id = deleteApplication.ID
	user.FriendApplication = deleteApplication.FriendId
	user.AddType = deleteApplication.AddType
	return dao.DeleteApplication(user)
}
